package cn.tedu.coolshark.controller;

import cn.tedu.coolshark.base.response.JsonResult;
import cn.tedu.coolshark.mapper.CategoryMapper;
import cn.tedu.coolshark.pojo.entity.Category;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/category")
@Api(tags="分类模块管理")
public class CategoryController {
    @Autowired
    private CategoryMapper categoryMapper;
    @GetMapping("/select")
    @ApiOperation(value = "查询所有分类")
    public List<Category> created(){
        return categoryMapper.selectAll();
    }

    @PostMapping("/delete")
    @ApiOperation(value = "根据id删除分类")
    @ApiImplicitParam(name = "id",value = "分类id",required = true)
    public int delete(Integer id){
        log.debug("id:"+id);
        return categoryMapper.delete(id);
    }

    @PostMapping("/insert")
    @ApiOperation(value = "添加分类")
    @ApiImplicitParam(name = "name",value = "分类名称",required = true)
    public int insert(String name){
        return categoryMapper.insert(name);
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改分类")
    @ApiImplicitParam(name = "category",value = "分类对象",required = true)
    public int update(@RequestBody Category category){
        return categoryMapper.update(category);
    }
}
